﻿using System;
using Microsoft.Xna.Framework;
using Terraria.DataStructures;

namespace Terraria.World.Generation
{
	// Token: 0x020000AC RID: 172
	public static class ModShapes
	{
		// Token: 0x020000AD RID: 173
		public class All : GenModShape
		{
			// Token: 0x06000A72 RID: 2674 RVA: 0x0000B3D3 File Offset: 0x000095D3
			public All(ShapeData data) : base(data)
			{
			}

			// Token: 0x06000A73 RID: 2675 RVA: 0x003E6000 File Offset: 0x003E4200
			public override bool Perform(Point origin, GenAction action)
			{
				foreach (Point16 point in this._data.GetData())
				{
					if (!base.UnitApply(action, origin, (int)point.X + origin.X, (int)point.Y + origin.Y, new object[0]) && this._quitOnFail)
					{
						return false;
					}
				}
				return true;
			}
		}

		// Token: 0x020000AE RID: 174
		public class OuterOutline : GenModShape
		{
			// Token: 0x06000A74 RID: 2676 RVA: 0x0000B3DC File Offset: 0x000095DC
			public OuterOutline(ShapeData data, bool useDiagonals = true, bool useInterior = false) : base(data)
			{
				this._useDiagonals = useDiagonals;
				this._useInterior = useInterior;
			}

			// Token: 0x06000A75 RID: 2677 RVA: 0x003E608C File Offset: 0x003E428C
			public override bool Perform(Point origin, GenAction action)
			{
				int num = this._useDiagonals ? 16 : 8;
				foreach (Point16 point in this._data.GetData())
				{
					if (this._useInterior && !base.UnitApply(action, origin, (int)point.X + origin.X, (int)point.Y + origin.Y, new object[0]) && this._quitOnFail)
					{
						return false;
					}
					for (int i = 0; i < num; i += 2)
					{
						if (!this._data.Contains((int)point.X + ModShapes.OuterOutline.POINT_OFFSETS[i], (int)point.Y + ModShapes.OuterOutline.POINT_OFFSETS[i + 1]) && !base.UnitApply(action, origin, origin.X + (int)point.X + ModShapes.OuterOutline.POINT_OFFSETS[i], origin.Y + (int)point.Y + ModShapes.OuterOutline.POINT_OFFSETS[i + 1], new object[0]) && this._quitOnFail)
						{
							return false;
						}
					}
				}
				return true;
			}

			// Token: 0x04000EDE RID: 3806
			private static readonly int[] POINT_OFFSETS = new int[]
			{
				1,
				0,
				-1,
				0,
				0,
				1,
				0,
				-1,
				1,
				1,
				1,
				-1,
				-1,
				1,
				-1,
				-1
			};

			// Token: 0x04000EDF RID: 3807
			private bool _useDiagonals;

			// Token: 0x04000EE0 RID: 3808
			private bool _useInterior;
		}

		// Token: 0x020000AF RID: 175
		public class InnerOutline : GenModShape
		{
			// Token: 0x06000A77 RID: 2679 RVA: 0x0000B40C File Offset: 0x0000960C
			public InnerOutline(ShapeData data, bool useDiagonals = true) : base(data)
			{
				this._useDiagonals = useDiagonals;
			}

			// Token: 0x06000A78 RID: 2680 RVA: 0x003E61CC File Offset: 0x003E43CC
			public override bool Perform(Point origin, GenAction action)
			{
				int num = this._useDiagonals ? 16 : 8;
				foreach (Point16 point in this._data.GetData())
				{
					bool flag = false;
					for (int i = 0; i < num; i += 2)
					{
						if (!this._data.Contains((int)point.X + ModShapes.InnerOutline.POINT_OFFSETS[i], (int)point.Y + ModShapes.InnerOutline.POINT_OFFSETS[i + 1]))
						{
							flag = true;
							break;
						}
					}
					if (flag && !base.UnitApply(action, origin, (int)point.X + origin.X, (int)point.Y + origin.Y, new object[0]) && this._quitOnFail)
					{
						return false;
					}
				}
				return true;
			}

			// Token: 0x04000EE1 RID: 3809
			private static readonly int[] POINT_OFFSETS = new int[]
			{
				1,
				0,
				-1,
				0,
				0,
				1,
				0,
				-1,
				1,
				1,
				1,
				-1,
				-1,
				1,
				-1,
				-1
			};

			// Token: 0x04000EE2 RID: 3810
			private bool _useDiagonals;
		}
	}
}
